<?php

/**
 * 
 * Core_Model_Updatedata
 *
 * @author adrian
 */
class Core_Model_Updatedata implements Core_Model_Ormable {
    
    public $database_validation;
    
    public function main(array $variables = null, $table = null, $action = null, $where = '1') {
        $query="UPDATE `$table` SET ";

        foreach($variables as $key => $value){
            if(strtolower($value)=='null'){
                $query .= "`$key` = NULL, ";
            }
            elseif(strtolower($value)=='now()'){
                $query .= "`$key` = NOW(), ";
            }
            elseif(preg_match("/^increment\((\-?\d+)\)$/i",$value,$m)){
                $query .= "`$key` = `$key` + $m[1], "; 
            }
            else {
                $this->database_validation = new Core_Model_Databasevalidation;
                
                $query.= "`$key`= ".$this->database_validation->class_init($value).", ";
            }
        }

        $query = rtrim($query, ', ') . ' WHERE '.$where.';';
        return $query;

    }
    

}
